package com.origin.app.bean;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;


import com.origin.app.BR;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Index;
import org.greenrobot.greendao.annotation.Transient;

@Entity(indexes = {@Index(value = "address DESC", unique = true)})
public class UserProtectionAddressBean extends BaseObservable implements Parcelable {
    @Transient
    private static final long serialVersionUID = 1L;

    @Id(autoincrement = true)
    public Long id;

    private String address;
    private double latitude;
    private double longitude;
    private boolean collect;

    public UserProtectionAddressBean(String address, double latitude,
                                     double longitude, boolean collect) {
        this.address = address;
        this.latitude = latitude;
        this.longitude = longitude;
        this.collect = collect;
    }

    @Generated(hash = 1554427267)
    public UserProtectionAddressBean(Long id, String address, double latitude,
                                     double longitude, boolean collect) {
        this.id = id;
        this.address = address;
        this.latitude = latitude;
        this.longitude = longitude;
        this.collect = collect;
    }

    @Generated(hash = 682853831)
    public UserProtectionAddressBean() {
    }

    protected UserProtectionAddressBean(Parcel in) {
        if (in.readByte() == 0) {
            id = null;
        } else {
            id = in.readLong();
        }
        address = in.readString();
        latitude = in.readDouble();
        longitude = in.readDouble();
        collect = in.readByte() != 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        if (id == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeLong(id);
        }
        dest.writeString(address);
        dest.writeDouble(latitude);
        dest.writeDouble(longitude);
        dest.writeByte((byte) (collect ? 1 : 0));
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<UserProtectionAddressBean> CREATOR = new Creator<UserProtectionAddressBean>() {
        @Override
        public UserProtectionAddressBean createFromParcel(Parcel in) {
            return new UserProtectionAddressBean(in);
        }

        @Override
        public UserProtectionAddressBean[] newArray(int size) {
            return new UserProtectionAddressBean[size];
        }
    };

    @Bindable
    public boolean getCollect() {
        return collect;
    }

    public void setCollect(boolean collect) {
        this.collect = collect;
        notifyPropertyChanged(BR._all);
    }

    @Bindable
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
        notifyPropertyChanged(BR.address);
    }

    @Bindable
    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
        notifyPropertyChanged(BR.latitude);
    }

    @Bindable
    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
        notifyPropertyChanged(BR.longitude);
    }

    public void cloneDeep(UserProtectionAddressBean bean) {
        this.address = bean.address;
        this.latitude = bean.latitude;
        this.longitude = bean.longitude;
        this.collect = bean.collect;
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }
}
